﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlAgilityPack;

namespace FreeIMDB
{
    /// <summary>
    /// Provides a simple way to fetch the HTML source document of an IMDB movie page.
    /// </summary>
    class MovieDownloader : IHtmlDownloader
    {
        HtmlWeb downloader = new HtmlWeb();
        
        /// <summary>
        /// Find a movie page using only the name.
        /// </summary>
        /// <param name="name">Movie name</param>
        /// <returns>Returns an HtmlDocument with the source code included.</returns>
        public HtmlDocument ByName(string name)
        {
            string url = findURL(name);
            HtmlDocument page = downloader.Load(url);
            return page;
        }

        /// <summary>
        /// Find a movie page using its precise IMDB id.
        /// </summary>
        /// <param name="id">IMDB Movie ID</param>
        /// <returns>Returns an HtmlDocument with the source code included.</returns>
        public HtmlDocument ByID(string id)
        {
            string url = String.Format("http://www.imdb.com/title/tt{0}/", id.PadLeft(7,'0'));            
            HtmlDocument page = downloader.Load(url);
            return page;
        }

        private string findURL(string name)
        {
            //To be implemented!
            return null;
        }
    }
}
